package com.example.lib_base.base;

import android.content.res.Resources;
import android.os.Bundle;
import android.provider.CalendarContract;

import com.example.lib_base.R;
import com.example.lib_base.utils.BarUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

public abstract class BaseDBActivity extends DataBindingActivity {
    //自己viewModel
    private ViewModelProvider mActivityProvider;

    //全局viewModel
    private ViewModelProvider mApplicationProvider;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        BarUtils.setStatusBarColor(this, getColor(R.color.colorPrimary));
        BarUtils.setStatusBarLightMode(this, true);
        super.onCreate(savedInstanceState);
    }

    protected <T extends ViewModel> T getActivityScopeViewModel(@NonNull Class<T> modelClass) {
        if (mActivityProvider == null) {
            mActivityProvider = new ViewModelProvider(this);
        }
        return mActivityProvider.get(modelClass);
    }

    protected <T extends ViewModel> T getApplicationScopeViewModel(@NonNull Class<T> modelClass) {
        if (mApplicationProvider == null) {
            mApplicationProvider = new ViewModelProvider((BaseApplication) this.getApplicationContext());
        }
        return mApplicationProvider.get(modelClass);
    }
}
